package server.business.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import server.business.mapper.BloodTransferDetailMapper;
import server.business.pojo.BloodTransferDetail;
import server.business.service.BloodTransferDetailService;

import java.util.List;

@Service
public class BloodTransferDetailServiceImpl extends ServiceImpl<BloodTransferDetailMapper, BloodTransferDetail>
        implements BloodTransferDetailService {

    @Autowired
    BloodTransferDetailMapper bloodTransferDetailMapper;

    @Override
    public List<BloodTransferDetail> getAll(String number) {
        LambdaQueryWrapper<BloodTransferDetail> queryWrapper = new LambdaQueryWrapper<BloodTransferDetail>();
        queryWrapper.eq(BloodTransferDetail::getApplyId, number);
        List<BloodTransferDetail> list = bloodTransferDetailMapper.selectList(queryWrapper);
        return list;
    }

    /**
     * 删除信息
     * @param string
     */
    @Override
    public void clear(String string) {
        LambdaQueryWrapper<BloodTransferDetail> queryWrapper = new LambdaQueryWrapper<BloodTransferDetail>();
        queryWrapper.eq(BloodTransferDetail::getApplyId,string);
        bloodTransferDetailMapper.delete(queryWrapper);
    }

    @Override
    public void addOne(BloodTransferDetail bloodTransferDetail) {
        bloodTransferDetailMapper.insert(bloodTransferDetail);
    }

    /**
     * 修改调血申请
     * @param bloodTransferDetail
     */
    @Override
    public void revise(BloodTransferDetail bloodTransferDetail) {
        clear(bloodTransferDetail.getApplyId());
        bloodTransferDetailMapper.insert(bloodTransferDetail);
    }
}
